package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.domain.PmsProductAttributeValue;
import com.itheima.domain.PmsProductFullReduction;
import com.itheima.mapper.PmsProductFullReductionMapper;
import com.itheima.service.db.PmsProductFullReductionService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class PmsProductFullReductionServiceImpl implements PmsProductFullReductionService {
    @Autowired
    PmsProductFullReductionMapper pmsProductFullReductionMapper;

    @Override
    public List<PmsProductFullReduction> selectByProductId(Integer id) {
        LambdaQueryWrapper<PmsProductFullReduction> lqw=new LambdaQueryWrapper<>();
        lqw.eq(PmsProductFullReduction::getProductId,id);
        return pmsProductFullReductionMapper.selectList(lqw);
    }


    @Override
    public void updateByProductId(Integer id, List<PmsProductFullReduction> PmsProductFullReductionList) {
        LambdaQueryWrapper<PmsProductFullReduction> lqw=new LambdaQueryWrapper<>();
        lqw.eq(PmsProductFullReduction::getProductId,id);
        pmsProductFullReductionMapper.delete(lqw);

        for (PmsProductFullReduction PmsProductFullReduction : PmsProductFullReductionList) {
            PmsProductFullReduction.setProductId(id.longValue());
            pmsProductFullReductionMapper.insert(PmsProductFullReduction);
        }

    }

    @Override
    public void save(Long productId, List<PmsProductFullReduction> productFullReductionList) {
        for (PmsProductFullReduction PmsProductFullReduction : productFullReductionList) {
            PmsProductFullReduction.setProductId(productId);
            pmsProductFullReductionMapper.insert(PmsProductFullReduction);
        }
    }
}
